package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.jjy.duss.yy.Z_IF_MD089;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-01-07
 * @Description: 供应商撤场清户申请推送SAP
 * @ModifyLog:
 **/

public class WeaHRCcqhtsAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        User user = requestInfo.getRequestManager().getUser();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用Action: WeaHRCcqhtsAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select cclzddh,zt from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select cclzddh,zt from " + tablename + " where requestid=?" + requestid);
        rs.next();
        String cclzddh = Util.null2String(rs.getString("cclzddh"));//撤场流转单单号
        String zt = Util.null2String(rs.getString("zt"));//审批结果
        baseBean.writeLog(cclzddh+","+zt);
        Map<String, String> map = new HashMap();
        map.put("CCLZDNO", cclzddh);
        map.put("STATUS", zt);
        baseBean.writeLog("相关参数:" + map.toString());
        try{
            Z_IF_MD089 if_md089 = new Z_IF_MD089();
            Map resultMap = if_md089.execute(map);
            String flag = (String) resultMap.get("flag");
            String message = (String) resultMap.get("message");
            baseBean.writeLog("SAP返回结果——flag:" + flag + ";message:" + message);
            if("s".equalsIgnoreCase(flag)){
                return Action.SUCCESS;
            }else {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
                return Action.FAILURE_AND_CONTINUE;
            }
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("异常参考:" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}
